package com.exchange.util;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 
 * @author 李书文
 * @description 获取系统信息工具类
 * @time 2016年10月22日
 */
public class RuntimeUtil {

	public static void main(String[] args) {

	}

	public static Map<String, Object> property() throws UnknownHostException {
		Map<String, Object> object = new HashMap<String, Object>();
		Runtime r = Runtime.getRuntime();
		Properties props = System.getProperties();
		InetAddress addr;
		addr = InetAddress.getLocalHost();
		String ip = addr.getHostAddress();
		Map<String, String> map = System.getenv();
		String userName = map.get("USERNAME");// 获取用户名
		String computerName = map.get("COMPUTERNAME");// 获取计算机名

		object.put("userName", userName);
		object.put("computerName", computerName);
		object.put("ip", ip);
		object.put("HostName", addr.getHostName());
		object.put("Memory", r.totalMemory());
		object.put("freeMemory", r.freeMemory());
		object.put("Processors", r.availableProcessors());
		object.put("version", props.getProperty("java.version"));
		object.put("vendor", props.getProperty("java.vendor"));
		object.put("home", props.getProperty("java.home"));
		object.put("specification", props.getProperty("java.specification.version"));
		return object;
	}

	public static String getIp() {
		InetAddress addr;
		String ip = "";
		try {
			addr = InetAddress.getLocalHost();
			ip = addr.getHostAddress();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return ip;

	}
}
